package src.Fifteen;

import javafx.stage.WindowEvent;

import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.awt.event.ActionEvent;

public class ThreadPriorityTest {

    private JTable table;
    private JTextField textField;

    protected void do_this_windowActivated(WindowEvent e){
        ThreadGroup group = Thread.currentThread().getThreadGroup();
        Thread[] threads = new Thread[group.activeCount()];
        group.enumerate(threads);
        DefaultTableModel model = (DefaultTableModel) table.getModel();
        model.setRowCount(0);
        model.setColumnIdentifiers(new Object[]{"线程ID","线程名称","优先级"});
        for(Thread thread : threads){
            model.addRow(new Object[]{thread.getId(),thread.getName()});
            thread.getPriority();
        }
        table.setModel(model);
    }

    protected void do_button_actionPerformed(ActionEvent e){
        String text = textField.getText();
        Integer priority = Integer.parseInt(text);
        int selectedRow = table.getSelectedRow();
        DefaultTableModel model = (DefaultTableModel) table.getModel();
        model.setValueAt(priority,selectedRow,2);
        //repaint();
    }
}
